#!/usr/bin/env python
#coding=utf-8
import os 
import sys
import json
import time

#G_PATH = "/home/pi/hf_formation"
def readfile(filename): 
    contents = ""
    try:
        G_PATH = os.getcwd()
        fh = open(G_PATH + filename, 'r') 
        contents = fh.read()
        fh.close() 
    except Exception as e:
        print('readfile error:' + str(e))
        pass
    return contents
    
    
def savefile(filename, contents, ty='a'): 
    try:
        G_PATH = os.getcwd()
        fh = open(G_PATH + filename, ty) 
        fh.write(contents + "\n") 
    except Exception as e:
        print('savefile error:' + str(e))
    fh.close()
    
def is_valid_date(strdate):
    '''判断是否是一个有效的日期字符串'''
    try:
        if ":" in strdate:
            time.strptime(strdate, "%Y-%m-%d %H:%M:%S")
        else:
            time.strptime(strdate, "%Y-%m-%d")
        return True
    except:
        return False
